package com.ruoyi.web.controller.contest;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.contest.mapper.ContestScoreMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;

import com.ruoyi.contest.domain.ContestScore;
import com.ruoyi.contest.service.IContestScoreService;

import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 竞赛分值Controller
 *
 * @author ruoyi
 * @date 2023-02-23
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/contest/contestScore")
public class ContestScoreController extends BaseController
{
    @Resource
    private IContestScoreService contestScoreService;

    @Resource
    private ContestScoreMapper contestScoreMapper;

    /**
     * 查询竞赛分值列表
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:list')")
    @GetMapping("/list")
    public TableDataInfo list(ContestScore contestScore)
    {
        startPage();
        List<ContestScore> list = contestScoreService.selectContestScoreList(contestScore);
        return getDataTable(list);
    }

    /**
     * 导出竞赛分值列表
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:export')")
    @Log(title = "竞赛分值", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ContestScore contestScore)
    {
        List<ContestScore> list = contestScoreService.selectContestScoreList(contestScore);
        ExcelUtil<ContestScore> util = new ExcelUtil<ContestScore>(ContestScore.class);
        util.exportExcel(response, list, "竞赛分值数据");
    }

    /**
     * 获取竞赛分值详细信息
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:query')")
    @GetMapping(value = "/{contestScoreId}")
    public AjaxResult getInfo(@PathVariable("contestScoreId") Integer contestScoreId)
    {
        return success(contestScoreMapper.getById(contestScoreId));
    }

    /**
     * 新增竞赛分值
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:add')")
    @Log(title = "竞赛分值", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ContestScore contestScore)
    {
        return toAjax(contestScoreService.save(contestScore));
    }

    /**
     * 修改竞赛分值
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:edit')")
    @Log(title = "竞赛分值", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ContestScore contestScore)
    {
        contestScoreMapper.updateContestScoreRemark(contestScore.getContestScoreId(),contestScore.getRemark());
        return AjaxResult.success("修改成功");
    }

    /**
     * 删除竞赛分值
     */
    @PreAuthorize("@ss.hasPermi('contest:contestScore:remove')")
    @Log(title = "竞赛分值", businessType = BusinessType.DELETE)
	@DeleteMapping("/{contestScoreIds}")
    public AjaxResult remove(@PathVariable Long[] contestScoreIds)
    {
        return toAjax(contestScoreService.removeByIds(Arrays.asList(contestScoreIds)));
    }
}
